1 Public Class FrmSTOCKADD
2 Dim stockID As Integer
3 Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
4 Me.Close()
5 End Sub
6
7 Private Sub FrmSTOCKADD_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
8 Me.Text = "Stock Information"
9 End Sub
10
11 Private Sub FrmSTOCKADD_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
12 stockID = globalID
13 FILLComboBox("SELECT Supp_ID, SuppName FROM TBL_Suppliers", cmbsupplier)
14 If Split(Me.Text, " - ")(1) = "Add" Then
15 txtproductid.Text = ""
16 txtdesc.Text = ""
17 txtqty.Text = ""
18 txtbarcode.Text = ""
19 FormShow(FrmStockList, False, 0, 0)
20 Else
21 'sqlSTR = "SELECT * FROM "
22
23 End If
24
25 'If Split(Me.Text, " - ")(1) = "Edit" Then
26 ' stockID = globalID
27 ' sqlSTR = "SELECT * FROM tbl_Category_File WHERE catg_ID =" & stockID
28 ' ExecuteSQLQuery(sqlSTR)
29 ' If sqlDT.Rows.Count > 0 Then
30 ' txtid.Text = sqlDT.Rows(0)("Catg_ID")
31 ' txtname.Text = sqlDT.Rows(0)("Catg_Name")
32 ' txtdesc.Text = sqlDT.Rows(0)("Catg_Description")
33 ' End If
34 'Else
35 ' txtid.Text = ""
36 ' txtname.Text = ""
37 ' txtdesc.Text = ""
38 'End If
39 End Sub
40
41 Private Sub txtproductid_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtproductid.MouseClick
42 FrmStockList.ShowDialog()
43 End Sub
44
45 Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
46 If Not IsNumeric(txtqty.Text) Then
47 MsgBox("Quantity Should Be Numeric ", MsgBoxStyle.Information, "Sales and Inventory")
48 Exit Sub
49 End If
50 If txtproductid.Text = "" And txtdesc.Text = "" And txtbarcode.Text = "" And txtqty.Text = "" Then
51 MsgBox("No Corresponding Data Found !!", MsgBoxStyle.Information, "Sales and Inventory")
52 Exit Sub
53 End If
54 If cmbsupplier.Text = "" Then
55 MsgBox("Input Supplier Name", MsgBoxStyle.Information, "Sales and Inventory")
56 Exit Sub
57 End If
58
59 'sqlSTR = "INSERT INTO TBL_Stocks_Details (Item_ID, Item_Qty, Item_Description, Date_Purchased, Item_Consolidate) VALUES (" & txtproductid.Text & ", " _
60 ' & txtqty.Text & ", " _
61 ' & "'" & txtdesc.Text & "', " _
62 ' & dtPicker.Text & ", " _
63 ' & 0 & ")"
64 'ADD TO TBL_PURCHASE_ORDER
65 If Split(Me.Text, " - ")(1) = "Add" Then
66 sqlSTR = "INSERT INTO TBL_Purchase_Order (Supp_ID, Address, Delivery_Term, Approved, Purchased_Date, Received_Date, Direct_Input) " & _
67 " VALUES (" & Split(cmbsupplier.Text, " - ")(0) & ", " _
68 & "'" & txtaddress.Text & "', " _
69 & "'" & txtdelivery.Text & "', " _
70 & "'" & "Yes" & "', " _
71 & "'" & Format(dtPicker.Value, "MM/dd/yyyy") & "', " _
72 & "'" & Format(dtreceived.Value, "MM/dd/yyyy") & "', " _
73 & "'" & "Yes" & "')"
74 'MsgBox(sqlSTR)
75 ExecuteSQLQuery(sqlSTR)
76 'GET THE LAST ID
77 sqlSTR = "SELECT * FROM TBL_Purchase_Order ORDER BY Purchase_ID DESC"
78 ExecuteSQLQuery(sqlSTR)
79 'STORE THE LAST ID
80 stockID = sqlDT.Rows(0)("Purchase_ID")
81 sqlSTR = "INSERT INTO TBL_Purchase_Detail (Purchase_ID, Item_ID,Item_Qty) " & _
82 " VALUES (" & stockID & ", " _
83 & txtproductid.Text & ", " _
84 & txtqty.Text & ")"
85 'MsgBox(lstitems.Items(i).SubItems(4).Text)
86 ExecuteSQLQuery(sqlSTR)
87 'CHECK IF ITEM IS ALREADY EXISTS IN THE TABLE!
88 sqlSTR = "SELECT * FROM TBL_Stocks_Balances WHERE Item_ID =" & txtproductid.Text
89 ExecuteSQLQuery(sqlSTR)
90 If sqlDT.Rows.Count > 0 Then
91 ' sqlSTR = "UPDATE tbl_Category_File SET Catg_Name ='" & txtname.Text & "', " _
92 ' & "Catg_Description ='" & txtdesc.Text & "' WHERE catg_ID =" & stockID
93
94 sqlSTR = "UPDATE TBL_Stocks_Balances SET Item_Qty =" & sqlDT.Rows(0)("Item_QTY") + txtqty.Text & ", " _
95 & "Direct_Input ='" & "Yes" & "' WHERE Item_ID =" & txtproductid.Text
96 ExecuteSQLQuery(sqlSTR)
97
98 Else
99 'if the current record is not yet on TBL_Stock_Balances, Add the Data !
100 sqlSTR = "INSERT INTO TBL_Stocks_Balances (Item_ID, Item_QTY, Item_Description, DIRECT_INPUT) VALUES (" & txtproductid.Text & ", " _
101 & txtqty.Text & ", " _
102 & "'" & txtdesc.Text & "', " _
103 & "'" & "Yes" & "')"
104 ExecuteSQLQuery(sqlSTR)
105 End If
106 Audit_Trail(xUser_ID, TimeOfDay, "Add New Direct Stocks Add")
107 Else
108 'EDIT
109 sqlSTR = "SELECT * FROM TBL_Stocks_Balances WHERE Item_ID =" & txtproductid.Text
110 ExecuteSQLQuery(sqlSTR)
111 If sqlDT.Rows.Count > 0 Then
112 ' sqlSTR = "UPDATE tbl_Category_File SET Catg_Name ='" & txtname.Text & "', " _
113 ' & "Catg_Description ='" & txtdesc.Text & "' WHERE catg_ID =" & stockID
114
115 sqlSTR = "UPDATE TBL_Stocks_Balances SET Item_Qty =" & sqlDT.Rows(0)("Item_QTY") + txtqty.Text & ", " _
116 & "Direct_Input ='" & "Yes" & "' WHERE Item_ID =" & txtproductid.Text
117 ExecuteSQLQuery(sqlSTR)
118 Else
119 'if the current record is not yet on TBL_Stock_Balances, Add the Data !
120 sqlSTR = "INSERT INTO TBL_Stocks_Balances (Item_ID, Item_QTY, Item_Description, DIRECT_INPUT) VALUES (" & txtproductid.Text & ", " _
121 & txtqty.Text & ", " _
122 & "'" & txtdesc.Text & "', " _
123 & "'" & "Yes" & "')"
124 ExecuteSQLQuery(sqlSTR)
125 End If
126 Audit_Trail(xUser_ID, TimeOfDay, "Edit Item by Direct Stocks")
127 End If
128 sqlSTR = "SELECT TBL_category_item_file.item_id AS 'ID', TBL_Category_Item_File.Item_name as 'Name', TBL_Category_Item_File.Item_Description as 'Description / Item Number', TBL_Category_Item_File.item_price as 'Price', TBL_Stocks_Balances.Item_QTY as 'Quantity' , (tbl_stocks_balances.item_qty * tbl_category_item_file.item_price) as 'Total', DIRECT_INPUT AS 'DIRECT' " & _
129 "FROM TBL_category_item_file INNER JOIN TBL_Stocks_Balances ON TBL_Category_Item_File.Item_ID = TBL_Stocks_Balances.Item_ID "
130 FillListView(ExecuteSQLQuery(sqlSTR), frmSTOCKMONITORINGBALANCES.listStocks, 0)
131 Me.Close()
132 End Sub
133 End Class